package com.qf.smartdevice.controller;

import com.qf.smartdevice.dto.R;
import com.qf.smartdevice.pojo.Area;
import com.qf.smartdevice.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/areas")
public class AreaController {
    @Autowired
    private IAreaService areaService;

    //获取所有的父区域  没有上一级区域的区域就是父区域
    //元数据:描述数据的数据叫元数据
    @GetMapping("/areas/parent")
    public R getAllParentArea(){
        List<Area> allParentArea = areaService.getAllParentArea();
        return R.setOK(allParentArea);
    }

    @GetMapping("area/parent/{parentId}")
    public R getAllParentArea(@PathVariable Long parentId){
        List<Area> areaList = areaService.getAllAreasByParentId(parentId);
        return R.setOK(areaList);
    }
}
